//
//  NewResumeController.m
//  Ten
//
//  Created by anfuer on 2018/10/31.
//  Copyright © 2018年 xg韦. All rights reserved.
//

#import "NewResumeController.h"
#import "PickerToolView.h"
#import "YMCitySelect.h"
#import "HooDatePicker.h"
@interface NewResumeController ()<YMCitySelectDelegate,HooDatePickerDelegate>
@property (weak, nonatomic) IBOutlet UITextField *tsf1;
@property (weak, nonatomic) IBOutlet UITextField *tsf2;
@property (weak, nonatomic) IBOutlet UITextField *tsf3;
@property (weak, nonatomic) IBOutlet UIButton *btn1o;
@property (weak, nonatomic) IBOutlet UIButton *btn2o;
@property (weak, nonatomic) IBOutlet UIButton *btn3o;
@property (weak, nonatomic) IBOutlet UIButton *btn4o;
@property (weak, nonatomic) IBOutlet UIButton *btn5o;
@property (weak, nonatomic) IBOutlet UILabel *titiLb1;
@property (nonatomic, strong) HooDatePicker *datePicker;
@end

@implementation NewResumeController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.datePicker = [[HooDatePicker alloc] initWithSuperView:self.view];
    self.datePicker.delegate = self;
    self.datePicker.datePickerMode = HooDatePickerModeDate;
    NSDateFormatter *dateFormatter = [NSDate shareDateFormatter];
    [dateFormatter setDateFormat:kDateFormatYYYYMMDD];
    NSDate *maxDate = [NSDate date];
    NSDate *minDate = [dateFormatter dateFromString:@"1960-01-01"];
    [self.datePicker setDate:[NSDate date] animated:YES];
    self.datePicker.minimumDate = minDate;
    self.datePicker.maximumDate = maxDate;
    
    if (_resume_info) {
        _tsf1.text=_resume_info[@"name"];
        [_btn1o setTitle:[WXGStr(_resume_info[@"sex"]) isEqualToString:@"1"]?@"男":@"女" forState:UIControlStateNormal];
        [_btn2o setTitle:_resume_info[@"birthday"] forState:UIControlStateNormal];
        NSArray*tempary=@[@"其他",@"初中",@"高中",@"中专",@"大专",@"本科",@"硕士",@"博士",@"博士后"];
         [_btn3o setTitle:tempary[[_resume_info[@"education"]integerValue]] forState:UIControlStateNormal];
        NSArray*tempary2=@[@"一年",@"两年",@"三年",@"五年",@"五年以上"];
         [_btn4o setTitle:tempary2[[_resume_info[@"work_year"]integerValue]-1] forState:UIControlStateNormal];
        _tsf2.text=WXGStr(_resume_info[@"phone"]);
         _tsf3.text=WXGStr(_resume_info[@"email"]);
        [_btn5o setTitle:_resume_info[@"city"] forState:UIControlStateNormal];
        _titiLb1.text=@"修改基本信息";
    }
    
    
    
    // Do any additional setup after loading the view.
}
//选择基本信息  tag:0 性别  1出生年月 2学历 3工作年限 4城市
- (IBAction)changgeBtnas:(UIButton *)sender {
   
    [_tsf1 resignFirstResponder];
    [_tsf2 resignFirstResponder];
    [_tsf3 resignFirstResponder];
    if (sender.tag==1)
    {
        [self.datePicker show];
        
    }else if (sender.tag==4)
    {
        [self presentViewController:[[YMCitySelect alloc] initWithDelegate:self] animated:YES completion:nil];
        
    }else
    {
        
        NSArray *data = @[@[@"男",@"女"],@[],@[@"其他",@"初中",@"高中",@"中专",@"大专",@"本科",@"硕士",@"博士"],@[@"一年",@"两年",@"三年",@"五年",@"五年以上"]];
        PickerToolView *picker = [[PickerToolView alloc]init];
        picker.dataSource = data[sender.tag];
        picker.didSelectItem = ^(NSInteger idx){
            
            [sender setTitle:data[sender.tag][idx] forState:UIControlStateNormal];
            
        };
        [picker showWithAnimation:YES];
        
    }
    
    
}
- (IBAction)SaveBtna:(UIButton *)sender {
    if ([FuncPublic TextFieldisError:_tsf1]||[FuncPublic TextFieldisError:_tsf2]||[FuncPublic TextFieldisError:_tsf3]) {
        if ([[_btn1o currentTitle]isEqualToString:@"请选择"]||[[_btn2o currentTitle]isEqualToString:@"请选择"]||[[_btn3o currentTitle]isEqualToString:@"请选择"]||[[_btn4o currentTitle]isEqualToString:@"请选择"]||[[_btn5o currentTitle]isEqualToString:@"请选择"]) {
             [WSProgressHUD showImage:nil status:@"请完整个人资料再提交"];
              return;
        }
        
        NSMutableDictionary*mdic=[NSMutableDictionary dictionary];
        [mdic setObject:_tsf1.text forKey:@"name"];
        [mdic setObject:[[_btn1o currentTitle]isEqualToString:@"男"]?@"1":@"2" forKey:@"sex"];
        [mdic setObject:[_btn2o currentTitle] forKey:@"birthday"];
        NSArray*tempary=@[@"其他",@"初中",@"高中",@"中专",@"大专",@"本科",@"硕士",@"博士"];
        NSArray*tempary2=@[@"一年",@"两年",@"三年",@"五年",@"五年以上"];
        [mdic setObject:[NSString stringWithFormat:@"%lu",(unsigned long)[tempary indexOfObject:[_btn3o currentTitle]]] forKey:@"education"];
        [mdic setObject:[NSString stringWithFormat:@"%lu",(unsigned long)[tempary2 indexOfObject:[_btn4o currentTitle]]+1] forKey:@"work_year"];
         [mdic setObject:_tsf2.text forKey:@"phone"];
         [mdic setObject:_tsf3.text forKey:@"email"];
        [mdic setObject:[_btn5o currentTitle] forKey:@"city"];
        
        [FuncPublic getData:self parameters:mdic RequestUrl:_resume_info?sedit_resume:sadd_resume success:^(NSDictionary *acountInfo) {
            [WSProgressHUD showImage:nil status:acountInfo[@"msg"]];
            
        }];
   
    }
    
    
    
    
}
- (void)datePicker:(HooDatePicker *)datePicker didSelectedDate:(NSDate*)date {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //    [dateFormatter setLocale:[NSLocale currentLocale]];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *value = [dateFormatter stringFromDate:date];
    [_btn2o setTitle:value forState:UIControlStateNormal];
}
-(void)ym_ymCitySelectCityName:(NSString *)cityName{
    
    [_btn5o setTitle:cityName forState:UIControlStateNormal];
    
}


@end
